package com.servlet.album;

import com.util.DBUtil;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * @author yuisama
 * @date 2023/03/12 10:44
 **/
@WebServlet("/studio/album/withdraw.do")
public class WithdrawDoServlet extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //TODO:判断当前用户，取出uid，判断uid跟aid是否一致，不能把别人的作品下架了
        String aid = req.getParameter("aid");

        try(Connection c = DBUtil.connection()){
            String sql = "update albums set state = 0 where aid = ?";
            try(PreparedStatement ps = c.prepareStatement(sql)){
                ps.setString(1,aid);

                ps.executeUpdate();
            }
        }
        resp.sendRedirect("http://127.0.0.1:8080/studio/album/list.html");
        //更新后，重定向到这个页面，看起来没有发生一样

    }
}

